<div class="{{$viewClass['form-group']}}">

  <label class="{{$viewClass['label']}} control-label">{{$label}}</label>

  <div class="{{$viewClass['field']}}">

    @include('admin::form.error')

    <div {!! $attributes !!} style="width: 100%; height: 100%;">
      <select name="province{{$name}}"></select>&nbsp;
      <select name="city{{$name}}"></select>&nbsp;
      <select name="district{{$name}}"></select>
    </div>

    <input type="hidden" name="{{$name}}" value="{{ old($column, $value) }}"/>
    @include('admin::form.help-block')
  </div>
</div>

<script require="@area" init="{!! $selector !!}">
  Dcat.ready(function () {
    var old = "{{ $value }}";//赋值
    if (old) var oldsz = old.split("_");
    $this.distpicker({
      province: old ? oldsz[0] : '---- 所在省 ----',
      city: old ? oldsz[1] : '---- 所在市 ----',
      district: old ? oldsz[2] : '---- 所在区 ----',
      autoSelect: false,
    });

    //因提交时赋值，第一次不成功，第二次才正确赋值，因此只能监听select
    $("select[name='district" + "{{$name}}" + "']").on('change', () => {
      var province = $("select[name='province" + "{{$name}}" + "']").val();
      var city = $("select[name='city" + "{{$name}}" + "']").val();
      var district = $("select[name='district" + "{{$name}}" + "']").val();
      var nr = old ? old : '';
      if (province && city && district) {
        var nr = province + '_' + city + '_' + district;
      }
      $this.parents('.form-field').find('input[name={{ $name }}]').val(nr);
    });

  });
</script>
